<!doctype html>
<meta charset="utf-8">
<title>Test paint worklet loading</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script>
var host_info = get_host_info();

promise_test(function() {
  return CSS.paintWorklet.addModule("test_paint_worklet.js");
}, "Loading a paint worklet.");

promise_test(function(t) {
   var path = new URL("test_paint_worklet.js", document.location).pathname;
   var url = new URL(path, host_info.HTTP_REMOTE_ORIGIN);
   return promise_rejects_dom(t, "AbortError", CSS.paintWorklet.addModule(url));
}, "Loading a cross-origin paint worklet.");

promise_test(function(t) {
   return promise_rejects_dom(t, "AbortError", CSS.paintWorklet.addModule("nonexistent_worklet.js"));
}, "Loading a nonexistent paint worklet.");

promise_test(function(t) {
   return promise_rejects_dom(t, "AbortError", CSS.paintWorklet.addModule("syntax_error.js"));
}, "Loading a syntactically incorrect paint worklet.");

promise_test(function(t) {
   return promise_rejects_dom(t, "AbortError", CSS.paintWorklet.addModule("throw_exception.js"));
}, "Loading an exception-throwing paint worklet.");

promise_test(function(t) {
   return promise_rejects_dom(t, "AbortError", CSS.paintWorklet.addModule("test_paint_worklet.js"));
}, "Loading a paint worklet again.");

promise_test(function(t) {
   return promise_rejects_dom(t, "AbortError", CSS.paintWorklet.addModule("test_paint_worklet_empty_name.js"));
}, "Loading a paint worklet with an empty name.");

promise_test(function(t) {
   return promise_rejects_dom(t, "AbortError", CSS.paintWorklet.addModule("test_paint_worklet_properties_throws.js"));
}, "Loading a paint worklet whose inputProperties throws an exception.");

promise_test(function(t) {
   return promise_rejects_dom(t, "AbortError", CSS.paintWorklet.addModule("test_paint_worklet_arguments_throws.js"));
}, "Loading a paint worklet whose inputArguments throws an exception.");

promise_test(function(t) {
   return promise_rejects_dom(t, "AbortError", CSS.paintWorklet.addModule("test_paint_worklet_alpha_throws.js"));
}, "Loading a paint worklet whose alpha throws an exception.");

promise_test(function(t) {
   return promise_rejects_dom(t, "AbortError", CSS.paintWorklet.addModule("test_paint_worklet_not_constructor.js"));
}, "Loading a paint worklet which isn't a constructor function.");

promise_test(function(t) {
   return promise_rejects_dom(t, "AbortError", CSS.paintWorklet.addModule("test_paint_worklet_no_paint.js"));
}, "Loading a paint worklet with no paint.");

promise_test(function(t) {
   return promise_rejects_dom(t, "AbortError", CSS.paintWorklet.addModule("test_paint_worklet_paint_not_callable.js"));
}, "Loading a paint worklet with a paint that is not callable.");
</script>
